library(kableExtra) # biblioteca empleada para mejorar la estética de las tablas
library(dplyr)
##
## Attaching package: 'dplyr'
## The following object is masked from 'package:kableExtra':
##
## group_rows
## The following objects are masked from 'package:stats':
##
## filter, lag
## The following objects are masked from 'package:base':
##
## intersect, setdiff, setequal, union
dataframe <- read.csv("C:/Users/USUARIO/Desktop/Master/Segundo_Cuatri/Nueva carpeta/PRAC2/Documentos/pax_all_agreements_data.csv", header = T, sep = ";")
Una vez cargados los datos, se muestran en una tabla para poder ir conociéndolos mejor. Además, en la tabla que se muestra a continuación, se puede observar el tipo de variable del que se trata en cada ocasión.
rmarkdown::paged_table(dataframe)
En la tabla anterior se puede observar las diferentes variables contenidas en el dataset, así como el tipo de variable que se trata en cada ocasión. Como se puede observar, todas las variables se encuentran en el formato que se desea. Por lo tanto, no será necesaria ninguna modificación.
El primer paso en la limpieza de datos consistirá en realizar una búsqueda de valores perdidos, es decir, saber si existen observaciones para las cuales no se conoce su valor. Para ello, se utilizará la función propia de R “is.na()”. Recordar, que este es un paso muy importante, ya que algunas funciones de R podrían no funcionar de manera correcta en caso de haber valores nulos.
En el caso de encontrar valores Nan, habrá que decidir qué hacer con ellos. En el caso más trivial, siempre y cuando no representen un porcentaje elevado de observaciones, se podría optar por eliminar las filas en la que haya valores desconocidos. Sin embargo, en el caso de no considerar esto una buena práctica, existen otros métodos como sustituirlos por la media o la mediana de la variable a la que correspondan. En el caso, de elegir sustituir por la media de la variable, hay que prestar especial atención a que dicha variable no contenga valores extremos, ya que la media es un estadístico muy sensiblea este tipo de valores.
colSums(is.na(dataframe))%>% #Se analiza el número de Na que hay en cada variable
kbl() %>%
kable_styling()%>%
row_spec(row = 0, bold = T, color = "white", background = "#BE8F00")
| x | |
|---|---|
| Con | 0 |
| Contp | 0 |
| PP | 0 |
| PPName | 0 |
| Reg | 0 |
| AgtId | 0 |
| Ver | 0 |
| Agt | 0 |
| Dat | 0 |
| Status | 0 |
| Lgt | 0 |
| N_characters | 0 |
| Agtp | 0 |
| Stage | 0 |
| StageSub | 0 |
| Part | 0 |
| ThrdPart | 0 |
| OthAgr | 0 |
| Loc1ISO | 0 |
| Loc2ISO | 0 |
| Loc1GWNO | 11 |
| Loc2GWNO | 1622 |
| UcdpCon | 141 |
| UcdpAgr | 350 |
| PamAgr | 1835 |
| CowWar | 753 |
| GCh | 0 |
| GChRhet | 0 |
| GChAntid | 0 |
| GChSubs | 0 |
| GChOth | 0 |
| GDis | 0 |
| GDisRhet | 0 |
| GDisAntid | 0 |
| GDisSubs | 0 |
| GDisOth | 0 |
| GAge | 0 |
| GAgeRhet | 0 |
| GAgeAntid | 0 |
| GAgeSubs | 0 |
| GAgeOth | 0 |
| GMig | 0 |
| GMigRhet | 0 |
| GMigAntid | 0 |
| GMigSubs | 0 |
| GMigOth | 0 |
| GRa | 0 |
| GRaRhet | 0 |
| GRaAntid | 0 |
| GRaSubs | 0 |
| GRaOth | 0 |
| GRe | 0 |
| GReRhet | 0 |
| GReAntid | 0 |
| GReSubs | 0 |
| GReOth | 0 |
| GInd | 0 |
| GIndRhet | 0 |
| GIndAntid | 0 |
| GIndSubs | 0 |
| GIndOth | 0 |
| GOth | 0 |
| GOthRhet | 0 |
| GOthAntid | 0 |
| GOthSubs | 0 |
| GOthOth | 0 |
| GRef | 0 |
| GRefRhet | 0 |
| GRefSubs | 0 |
| GRefOth | 0 |
| GSoc | 0 |
| GSocRhet | 0 |
| GSocAntid | 0 |
| GSocSubs | 0 |
| GSocOth | 0 |
| GeWom | 0 |
| GeMe | 0 |
| GeMeNu | 0 |
| GeMeOth | 0 |
| GeLgbti | 0 |
| GeLgbtiPos | 0 |
| GeLgbtiNeg | 0 |
| GeFa | 0 |
| StDef | 0 |
| StGen | 0 |
| StCon | 0 |
| StSd | 0 |
| StRef | 0 |
| StSym | 0 |
| StInd | 0 |
| StUni | 0 |
| StBor | 0 |
| StXbor | 0 |
| Pol | 0 |
| PolGen | 0 |
| PolNewInd | 0 |
| PolNewTemp | 0 |
| ConRen | 0 |
| Cons | 0 |
| Ele | 0 |
| ElecComm | 0 |
| PolPar | 0 |
| PolParTrans | 0 |
| PolParOth | 0 |
| Civso | 0 |
| Tral | 0 |
| Pubad | 0 |
| Polps | 0 |
| PpsSt | 0 |
| PpsSub | 0 |
| PpsEx | 0 |
| PpsOro | 0 |
| PpsOthPr | 0 |
| PpsVet | 0 |
| PpsAut | 0 |
| PpsInt | 0 |
| PpsOth | 0 |
| Terps | 0 |
| TpsSub | 0 |
| TpsLoc | 0 |
| TpsAut | 0 |
| TpsOth | 0 |
| Eps | 0 |
| EpsRes | 0 |
| EpsFis | 0 |
| EpsOth | 0 |
| Mps | 0 |
| MpsMe | 0 |
| MpsJt | 0 |
| MpsPro | 0 |
| MpsOth | 0 |
| HrGen | 0 |
| EqGen | 0 |
| HrDem | 0 |
| Prot | 0 |
| ProtCiv | 0 |
| ProtGrp | 0 |
| ProtLgl | 0 |
| ProtOth | 0 |
| HrFra | 0 |
| HrfSp | 0 |
| HrfBor | 0 |
| HrfTinc | 0 |
| HrfOth | 0 |
| HrCp | 0 |
| CprLife | 0 |
| CprTort | 0 |
| CprEq | 0 |
| CprSlav | 0 |
| CprLib | 0 |
| CprDet | 0 |
| CprFmov | 0 |
| CprFspe | 0 |
| CprFass | 0 |
| CprTria | 0 |
| CprPriv | 0 |
| CprVote | 0 |
| CprReli | 0 |
| CprOth | 0 |
| HrSec | 0 |
| SerProp | 0 |
| SerWork | 0 |
| SerHeal | 0 |
| SerEdu | 0 |
| SerStdl | 0 |
| SerShel | 0 |
| SerSs | 0 |
| SerCult | 0 |
| SerOth | 0 |
| HrNi | 0 |
| HrNiMe | 0 |
| HrNiNe | 0 |
| HrNiOth | 0 |
| HrIi | 0 |
| HrIiMon | 0 |
| HrIiBod | 0 |
| HrIiOth | 0 |
| HrMob | 0 |
| HrDet | 0 |
| Med | 0 |
| MedGov | 0 |
| MedSubs | 0 |
| MedLog | 0 |
| MedOth | 0 |
| HrCit | 0 |
| CitGen | 0 |
| CitRights | 0 |
| CitDef | 0 |
| CitOth | 0 |
| JusCr | 0 |
| JusCrSp | 0 |
| JusCrSys | 0 |
| JusCrPow | 0 |
| JusEm | 0 |
| JusJu | 0 |
| JusPri | 0 |
| JusTra | 0 |
| Dev | 0 |
| DevSoc | 0 |
| DevHum | 0 |
| DevInfra | 0 |
| NEC | 0 |
| NatRes | 0 |
| IntFu | 0 |
| Bus | 0 |
| Tax | 0 |
| TaxPo | 0 |
| TaxRef | 0 |
| TaxOth | 0 |
| Ban | 0 |
| CenBan | 0 |
| BanPers | 0 |
| BanInt | 0 |
| BanXb | 0 |
| LaRef | 0 |
| LaRefMan | 0 |
| LaRefRet | 0 |
| LaRefOth | 0 |
| LaNom | 0 |
| LaCH | 0 |
| LaCHTa | 0 |
| LaCHIt | 0 |
| LaCHPro | 0 |
| LaCHOth | 0 |
| LaEn | 0 |
| Wat | 0 |
| SsrGua | 0 |
| Ce | 0 |
| CeProv | 0 |
| CeGen | 0 |
| SsrPol | 0 |
| SsrArm | 0 |
| SsrDdr | 0 |
| DdrDemil | 0 |
| DdrProg | 0 |
| SsrInt | 0 |
| SsrPsf | 0 |
| SsrFf | 0 |
| Cor | 0 |
| SsrCrOcr | 0 |
| SsrDrugs | 0 |
| Terr | 0 |
| TjGen | 0 |
| TjAm | 0 |
| TjAmPro | 0 |
| TjSan | 0 |
| TjPower | 0 |
| TjAmBan | 0 |
| TjCou | 0 |
| TjJaNc | 0 |
| TjJaIc | 0 |
| TjMech | 0 |
| TjPrire | 0 |
| TjVet | 0 |
| TjVic | 0 |
| TjMis | 0 |
| TjRep | 0 |
| TjRSym | 0 |
| TjRMa | 0 |
| TjNR | 0 |
| ImUN | 0 |
| ImOth | 0 |
| ImRef | 0 |
| ImPK | 0 |
| ImE | 0 |
| ImSrc | 0 |
| X | 1868 |
| X.1 | 1868 |
| X.2 | 1868 |
| X.3 | 1868 |
| X.4 | 1868 |
| X.5 | 1868 |
| X.6 | 1868 |
| X.7 | 1868 |
| X.8 | 1868 |
| X.9 | 1868 |
| X.10 | 1868 |
| X.11 | 1868 |
| X.12 | 1868 |
| X.13 | 1868 |
| X.14 | 1868 |
| X.15 | 1868 |
| X.16 | 1868 |
| X.17 | 1868 |
| X.18 | 1868 |
| X.19 | 1868 |
Como se puede observar en la tabla anterior, en un primer momento, parece que no hay ningún valor perdido en las variables que se tienen pensado utilizar en las visualizaciones.
Tras este análisis previo, se concluye que se puede trabajar con la base de datos original debido a que no hay ninguna variable que necesite ser modificada.